﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="2.0">
<xsl:output method="html" encoding="UTF-8"/>

<xsl:template match="r_int">
  <td><xsl:value-of select="current()"/></td>
  <td>&#160;</td>
</xsl:template>

<xsl:template match="Scenario">
  <xsl:variable name="SPAN" select="count(current()//r_ints)"/>
  <tr>
    <td rowspan="{$SPAN}"><xsl:value-of select="scenario_name"/><!--p size="-3"><xsl:value-of
      select="scenario_description"/></p--></td>
    <td rowspan="{$SPAN}"><xsl:value-of select="scenario_chains[1]/chain_sender/s_sys"/></td>
    <td rowspan="{$SPAN}">&#160;</td>
    <td rowspan="{$SPAN}"><xsl:value-of select="scenario_chains[1]/chain_sender/s_int"/></td>
    <td rowspan="{count(scenario_chains[1]/chain_receivers[1]/r_ints)}"><xsl:value-of
      select="scenario_chains[1]/chain_receivers[1]/r_sys"/></td>
    <td>&#160;</td>
    <td><xsl:value-of select="scenario_chains[1]/chain_receivers[1]/r_ints/r_int"/></td>
    <td rowspan="{$SPAN}">&#160;</td>
    <td rowspan="{$SPAN}">&#160;</td>
    <td rowspan="{$SPAN}">&#160;</td>
    <td rowspan="{$SPAN}">&#160;</td>
    <td rowspan="{$SPAN}">&#160;</td>
    <td>&#160;</td>
  </tr>
  <xsl:for-each select="scenario_chains[1]/chain_receivers[1]/r_ints[position()>1]/r_int">
    <tr><td>&#160;</td><xsl:apply-templates select="current()"/></tr>
  </xsl:for-each>

  <xsl:for-each select="scenario_chains[1]/chain_receivers[position()>1]|scenario_chains[position()>1]/chain_receivers">
    <tr>
      <td rowspan="{count(r_ints)}"><xsl:value-of select="r_sys"/></td>
      <td>&#160;</td>
      <xsl:apply-templates select="r_ints[1]/r_int"/>
      <xsl:for-each select="r_ints[position()>1]/r_int">
        <tr><td>&#160;</td>
          <xsl:apply-templates select="current()"/>
        </tr>
      </xsl:for-each>
    </tr>
  </xsl:for-each>
  </xsl:template>
  
  <xsl:template match="/root">
  <html><head><title></title></head>
  <body>
  <table border="1">
    <thead>
      <tr>
        <td rowspan="2">имя сценария</td>
        <td rowspan="2">бизнес-система -- источник данных</td>
        <td colspan="2">исходящий интерфейс</td>
        <td rowspan="2">бизнес-система -- приёмник данных</td>
        <td colspan="2">входящий интерфейс</td>
        <td colspan="2">размер сообщения по этому интерфейсу (килобайт)</td>
        <td rowspan="2">количество сообщений в день</td>
        <td rowspan="2">регламент прихода сообщений</td>
        <td rowspan="2">максимально допустимое время ожидания прихода сообщения в систему-приёмник</td>
        <td rowspan="2">особенности</td>
      </tr>
      <tr>
        <td>синхр</td>
        <td>асинхр</td>
        <td>синхр</td>
        <td>асинхр</td>
        <td>мин</td>
        <td>макс</td>
      </tr>
    </thead>
    <tbody>
      <xsl:apply-templates select="Scenario"/>
      <!--xsl:apply-templates 
        select="Scenario[count(scenario_chains)=1 and count(scenario_chains/chain_receivers)=1]"/>
      <xsl:apply-templates 
      select="Scenario[count(scenario_chains)=1 and count(scenario_chains/chain_receivers)>1]"/>
      <xsl:apply-templates      select="Scenario[scenario_name='DLVRY_PLAN']"/-->
    </tbody>
    
  </table>  
    
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
